<template>
	<div>
		<el-row :gutter="20">
		  	<el-col :span="24">
		  		<el-card class="box-card">
					<el-form v-loading="loading" :inline="false" ref="form" :model="form" label-width="100px">
			  			<el-form-item label="姓名："  prop="nickname" :rules="[{ required: true, message: '请填写用户姓名'}]"	>
			    			<el-input v-model="form.nickname" maxlength="10" class="input" placeholder="请输入用户姓名" show-word-limit clearable></el-input>
			  			</el-form-item>
						<el-form-item label="账号："  prop="username" :rules="[{ required: true, message: '请填写登录账号'}]"	>
							<el-input v-model="form.username" maxlength="20" class="input" placeholder="请输入登录账号" show-word-limit clearable></el-input>
						</el-form-item>
						<el-form-item label="密码：" prop="password" :rules="[{ required: true, message: '请填写默认密码'}]"	>
							<el-input v-model="form.password" maxlength="15" class="input" placeholder="请输入默认密码" show-word-limit clearable></el-input>
						</el-form-item>
						<el-form-item label="手机：" prop="telephone" >
							<el-input v-model="form.telephone"  maxlength="11" class="input" placeholder="请输入手机号码" show-word-limit clearable oninput="value=value.replace(/[^\d.]/g,'')"></el-input>
						</el-form-item>

			  		</el-form>
				</el-card>
		  	</el-col>
		</el-row>
	</div>
</template>

<script>
	export default{
		data() {
			return {
				loading:false,
				form:{
					"username":"",
					"nickname":"",
					"password":"",
					"telephone":""
				}
			}
		},
		methods:{
			reset(){
				this.$refs.form.resetFields();
			},
			save() {
        		this.$refs['form'].validate((valid) => {
        			if (valid) {
                        this.loading=true;
                        this.$http.post('user/addUser',{
                            "username":this.form.username,
                            "nickname":this.form.nickname,
                            "telephone":this.form.telephone,
                            "password":this.$md5(this.form.password),
                            "token":sessionStorage.getItem("token")
                        }).then(response => {
                            var data= response.body;
                            if(data.code==0){
                                this.reset();
                                this.$emit('dialogResult');
                            }
                            this.alertMsg(data.code,data.msg);
                            this.loading=false;
                        });
          			}
        		});
      		}
		}
	}
</script>

<style scoped="scoped">
	.input{
		width: 300px;
	}
</style>